{extend name="common/base" /}
{block name="content"}
    <div class="iframe_div layui-anim layui-anim-upbit">

        {if power('plugin_set_store','新建插件设置','plugin')}
        <fieldset>
            <legend>新增设置</legend>
            <form class="layui-form layui-form-pane form-search" action="" lay-filter="op_form">

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-inline" style="width: 120px">
                        <input type="text" name="name" lay-verify="required" value="" autocomplete="off" placeholder="名称" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">唯一标识</label>
                    <div class="layui-input-inline" style="width: 120px">
                        <input type="text" name="key" lay-verify="required" value="" autocomplete="off" placeholder="唯一标识" class="layui-input">
                    </div>
                </div>
                <button class="layui-btn search_btn" lay-submit="" lay-filter="save_sub_item">新增</button>

            </form>
        </fieldset>
        {/if}

        <form class="layui-form layui-form-pane" action="" lay-filter="op_form">

            {volist name="set" id="vo"}
            <div class="layui-form-item">
                <label class="layui-form-label">{$vo.name}</label>
                <div class="layui-input-block input_param">
                    <input type="text" name="{$key}"  value="{$vo.value}" autocomplete="off" placeholder="{$vo.name}" class="layui-input">
                    <i class="layui-icon layui-icon-delete del_i" data="{$key}"></i>
                    <span class="desc_span">唯一标识：{$key}</span>
                </div>
            </div>
            {/volist}

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="save_sub">设置</button>
                </div>
            </div>
        </form>
    </div>
{/block}
{block name="script"}
<script>
    layui.config({
        base: '<?php echo SITE;?>static/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index'],async () => {
        const { layer,form, admin, table, $,element } = layui;

        /*监听提交*/
        form.on('submit(save_sub)', function(data){
            data =data.field;
            let type = 'PUT';
            let url = '/admin/plugin/{$id}';

            $.ajax({
                type: type,
                url: url,
                data: data,
                datatype: 'json',
                success: function (res) {
                    if (res.status) {
                        layer.closeAll();
                    }
                    layer.msg(res.msg);
                }
            });
            return false;
        });
        /*监听新增*/
        form.on('submit(save_sub_item)', function(data){
            data =data.field;
            let type = 'POST';
            let url = '/admin/plugin_set/{$id}';

            $.ajax({
                type: type,
                url: url,
                data: data,
                datatype: 'json',
                success: function (res) {
                    layer.msg(res.msg);
                    if (res.status) {
                        setTimeout(function (){
                            window.location.reload();
                        },1000)
                    }
                }
            });
            return false;
        });

        /*删除配置*/
        $(".del_i").on('click',async function (){
            let key = $(this).attr('data');
            layer.confirm('真的删除'+key+'吗？',async function(index){
                await admin.delete('/admin/plugin_set/{$id}/'+key,index,false,true)
            });
        });



    });
</script>
{/block}


{block name="template"}
{/block}